package com.open.capacity.workflow3.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.user.service.SysFileService;
import com.open.capacity.workflow3.entity.BaseStamp;
import com.open.capacity.workflow3.service.BaseStampService;
import com.open.capacity.workflow3.service.NwfTaskService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author
 * @email
 * @date 2023-11-02 21:21:15
 */
@RestController
@RequestMapping("basestamps")
@Api(tags = "")
public class BaseStampController {


    @Autowired
    private BaseStampService baseStampService;

    @Autowired
    private SysFileService fileService;

    @GetMapping("/getPageList")
    public PageResult getPageList(@RequestParam Map<String, Object> param) {
        PageResult pageResult = baseStampService.getPageList(param);
        return pageResult;

    }

    @GetMapping("/getList")
    public Result getList(String keyword) {
        List<BaseStamp> data = baseStampService.getList(keyword);
        return Result.succeed(data);
    }

    @GetMapping("/getImg")
    public Result getImg(String keyValue, HttpServletResponse response, HttpServletRequest request) {
        baseStampService.getImg(keyValue, response, request);
        return Result.succeed("获取成功！");
    }

    @PostMapping("/save")
    public Result save(String keyValue, BaseStamp entity) {
        baseStampService.save(keyValue, entity);
        return Result.succeed("保存成功。");
    }

    @RequestMapping("/delete")
    public Result delete(String keyValue) {
        baseStampService.delete(keyValue);
        return Result.succeed("删除成功！");
    }

    @RequestMapping("/updateState")
    public Result updateState(String keyValue, int state) {
        baseStampService.updateState(keyValue, state);
        return Result.succeed(((state == 1) ? "启用" : "禁用") + "成功！");
    }

    @RequestMapping("/equalForm")
    public Result equalForm(String keyValue, String password) {
        if (baseStampService.equalPassword(keyValue, password)) {
            return Result.succeed("密码验证成功！");
        }
        return Result.failed("密码不正确！");
    }
}
